# Table
load('02_25_m5s_pp_fora_net_stats_list.RData')

tbl_to_print <-
  rbind(as.numeric(net_statistics$m5s$direct_reply),
        as.numeric(net_statistics$pp$direct_reply),
        as.numeric(net_statistics$m5s$bi),
        as.numeric(net_statistics$pp$bi))
colnames(tbl_to_print) <- 
  c('n', 'e', 'c', 'N (%)', 
    'U (mean)', 'D (mean)', 'T', 'D cor')
rownames(tbl_to_print) <- c("M5S direct reply", "PP direct reply", 
                            "M5S bipartite", "PP bipartite")
tbl_to_print <- as.data.frame(tbl_to_print)
tbl_to_print[,4] <- tbl_to_print[,4] * 100

load('02_25_m5s_pp_fora_nets_df_for_ggplot.RData')


require(ggplot2)
ggplot_bi_outdegree <- 
  ggplot(bi_outdegree_tbl_melted, aes(x=as.numeric(outdegree), y=value, colour=variable)) +
  geom_point(shape = 1) +
  scale_x_log10(
    breaks = scales::trans_breaks("log10", function(x) 10^x),
    labels = scales::trans_format("log10", scales::math_format(10^.x))
  ) +
  scale_y_log10(
    breaks = scales::trans_breaks("log10", function(x) 10^x),
    labels = scales::trans_format("log10", scales::math_format(10^.x))
  ) +
  annotation_logticks() +
  labs(title="Bipartite network", y='Number of nodes (log)', x='Outdegree (log)', colour=NULL)

ggplot_bi_indegree <-
  ggplot(bi_indegree_tbl_melted, aes(x=as.numeric(indegree), y=value, colour=variable)) +
  geom_point(shape = 1) +
  scale_x_log10(
    breaks = scales::trans_breaks("log10", function(x) 10^x),
    labels = scales::trans_format("log10", scales::math_format(10^.x))
  ) +
  scale_y_log10(
    breaks = scales::trans_breaks("log10", function(x) 10^x),
    labels = scales::trans_format("log10", scales::math_format(10^.x))
  ) +
  annotation_logticks() +
  labs(title="Bipartite network", y='Number of nodes (log)', x='Indegree (log)', colour=NULL)

ggplot_direct_indegree <- 
  ggplot(direct_reply_indegree_tbl_melted, aes(x=as.numeric(indegree), y=value, colour=variable)) +
  geom_point(shape = 1) +
  scale_x_log10(
    breaks = scales::trans_breaks("log10", function(x) 10^x),
    labels = scales::trans_format("log10", scales::math_format(10^.x))
  ) +
  scale_y_log10(
    breaks = scales::trans_breaks("log10", function(x) 10^x),
    labels = scales::trans_format("log10", scales::math_format(10^.x))
  ) +
  annotation_logticks() +
  labs(title="Direct reply network", y='Number of nodes (log)', x='Indegree (log)', colour=NULL)

ggplot_direct_outdegree <- 
  ggplot(direct_reply_outdegree_tbl_melted, aes(x=as.numeric(outdegree), y=value, colour=variable)) +
  geom_point(shape = 1) +
  scale_x_log10(
    breaks = scales::trans_breaks("log10", function(x) 10^x),
    labels = scales::trans_format("log10", scales::math_format(10^.x))
  ) +
  scale_y_log10(
    breaks = scales::trans_breaks("log10", function(x) 10^x),
    labels = scales::trans_format("log10", scales::math_format(10^.x))
  ) +
  annotation_logticks() +
  labs(title="Direct reply network", y='Number of nodes (log)', x='Outdegree (log)', colour=NULL)

ggplot_permanence <- 
  ggplot(diff_tbl_melted, aes(x=as.numeric(Permanence)+1, y=value, colour=variable)) +
  geom_point(shape = 1)  +
  scale_x_log10(
    breaks = scales::trans_breaks("log10", function(x) 10^x),
    labels = scales::trans_format("log10", scales::math_format(10^.x))
  ) +
  scale_y_log10(
    breaks = scales::trans_breaks("log10", function(x) 10^x),
    labels = scales::trans_format("log10", scales::math_format(10^.x))
  ) +
  annotation_logticks() +
  labs(y='Number of users (log)', x='Days + 1 (log)', colour=NULL)

require(gridExtra)

# Figure 5.14
grid.arrange(ggplot_bi_indegree, ggplot_bi_outdegree,
             ggplot_direct_indegree, ggplot_direct_outdegree)

# Figure 5.15
ggplot_permanence
